package com.kry.mbs.controller;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.jfinal.core.Controller;
import com.kry.mbs.common.ErrorType;
import com.kry.mbs.common.Response;
import com.kry.mbs.model.Meetingroom;

/*
 * 会议室管理
 * 
 */
public class MeetingroomController extends Controller {

	public void list() {
		StringBuilder sql = new StringBuilder(" SELECT * FROM meetingroom ");

		Map<String, String[]> paraMap = getParaMap();
		Set<String> keySet = paraMap.keySet();
		StringBuilder where = new StringBuilder(" WHERE 1=1 ");
		for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
			String key = (String) iterator.next();
			String value = paraMap.get(key)[0];
             if ("isVideo".equals(key)&&"-1".equals(value)) {
				continue;
			}
			where.append(" AND ").append(key).append("='").append(value).append("' ");
		}
		System.out.println("sql full:=" + sql.append(where).toString());

		List<Meetingroom> list = Meetingroom.dao.find(sql.toString());
		Response<List<Meetingroom>> response = new Response<List<Meetingroom>>(ErrorType.OK);
		response.setResult(list);
		renderJson(response);
	}

	public void save() {
		getModel(Meetingroom.class).save();
	}

	public void edit() {
		setAttr("meetingroom", Meetingroom.dao.findById(getParaToInt("id")));
	}

	public void update() {
		getModel(Meetingroom.class).update();
	}

	public void delete() {
		Meetingroom.dao.deleteById(getParaToInt());
	}

}
